<?php
class theme{
	private $app;
	private $outputType;
	private $outputPage;
	
	public function __construct(){
		global $app;
		$this->app =& $app;
		$app->{"theme"} =& $this;
	}
	
	/**
	 * 設定網頁輸出格式
	 * @param string $outputType
	 */
	public function setOutputType($outputType){
		$type = array(
			"html" => "text/html",
			"json" => "application/json",
			"xml" => "application/atom+xml"
		);
		$this->outputType = empty($type[$outputType])? $type["html"]: $type[$outputType];
	}
	
	/**
	 * 設定對應的佈景文件
	 * @param string $page
	 */
	public function setOutputPage($page = null){
		$this->outputPage = empty($page)? "index": ($page == "home"? "index": $page);
	}
	
	/**
	 * 輸出網頁
	 */
	public function output(){
		global $app;
		header('Content-type: '.$this->outputType);
		if(! @include(APP_PATH."theme/{$this->outputPage}.php"))
			app_die("佈景目錄內找不到 {$this->outputPage}.php");
	}
}
?>